Passed
Push — master ( f58e59...7370b8 )
by Maxence
04:18
created

pico_nav.deleteWebsite   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 13
rs 9.4285

1 Function

Rating   Name   Duplication   Size   Complexity  
A 0 5 2
1
/*
2
 * CMS Pico - Integration of Pico within your files to create websites.
3
 *
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the COPYING file.
6
 *
7
 * @author Maxence Lange <[email protected]>
8
 * @copyright 2017
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
/** global: OC */
27
/** global: pico_elements */
28
/** global: pico_result */
29
/** global: pico_define */
30
31
var pico_nav = {
32
33
	updateNewWebsite: function (url) {
34
		pico_elements.cms_pico_new_url.text(pico_define.nchost + pico_define.sites + url);
35
		pico_nav.refreshNewFolder();
36
	},
37
38
39
	pickFolderResult: function (folder) {
40
		pico_elements.cms_pico_new_folder_result = folder;
41
		pico_nav.refreshNewFolder();
42
	},
43
44
45
	refreshNewFolder: function () {
46
		pico_elements.cms_pico_new_folder.val(pico_elements.cms_pico_new_folder_result + '/' +
47
			pico_elements.cms_pico_new_website.val());
48
	},
49
50
51
	createNewWebsite: function () {
52
53
		pico_nav.creatingWebsite(true);
54
		var data = {
55
			name: pico_elements.cms_pico_new_name.val(),
56
			website: pico_elements.cms_pico_new_website.val(),
57
			path: pico_elements.cms_pico_new_folder.val(),
58
			template: pico_elements.cms_pico_new_template.val()
59
		};
60
61
		$.ajax({
62
			method: 'PUT',
63
			url: OC.generateUrl('/apps/cms_pico/personal/website'),
64
			data: {
65
				data: data
66
			}
67
		}).done(function (result) {
68
			pico_nav.creatingWebsite(false);
69
			pico_result.createNewWebsiteResult(result);
70
		});
71
72
	},
73
74
75
	deleteWebsite: function (id, name) {
76
77
		OC.dialogs.confirm(
78
			t('cms_pico',
79
				"This operation will delete the website {name} but its content will still be available in your files",
80
				{name: name}),
81
			t('cms_pico', 'Please confirm'),
82
			function (e) {
83
				if (e === true) {
84
					pico_nav.forceDeleteWebsite(id, name);
85
				}
86
			});
87
	},
88
89
90
	forceDeleteWebsite: function (id, name) {
91
		$.ajax({
92
			method: 'DELETE',
93
			url: OC.generateUrl('/apps/cms_pico/personal/website'),
94
			data: {
95
				data: {
96
					id: id,
97
					name: name
98
				}
99
			}
100
		}).done(function (result) {
101
			pico_result.deleteWebsiteResult(result);
102
		});
103
	},
104
105
106
	creatingWebsite: function (creating) {
107
108
		pico_elements.cms_pico_new_submit.prop('disabled', creating);
109
		if (creating) {
110
			pico_elements.cms_pico_new_submit.val(t('cms_pico', 'Please wait'));
111
		} else {
112
			pico_elements.cms_pico_new_submit.val(t('cms_pico', 'Create a new website'));
113
		}
114
115
	},
116
117
118
	updateWebsiteOption: function (site_id, key, value) {
119
		$.ajax({
120
			method: 'POST',
121
			url: OC.generateUrl('/apps/cms_pico/personal/website/' + site_id + '/option/' + key),
122
			data: {
123
				value: value
124
			}
125
		}).done(function (res) {
126
			pico_result.displayWebsites(res.websites);
127
		});
128
	},
129
130
131
	resetFields: function () {
132
		pico_elements.cms_pico_new_website.val('');
133
		pico_elements.cms_pico_new_name.val('');
134
		pico_elements.cms_pico_new_folder.val('/');
135
		pico_elements.cms_pico_new_url.text('');
136
	},
137
138
139
	generateTmplWebsite: function (entry) {
140
		var div = $('#tmpl_website');
141
		if (!div.length) {
142
			return;
143
		}
144
145
		var tmpl = div.html();
146
147
		tmpl = tmpl.replace(/%%id%%/g, entry.id);
148
		tmpl = tmpl.replace(/%%name%%/g, escapeHTML(entry.name));
149
		tmpl = tmpl.replace(/%%address%%/g, pico_define.nchost + pico_define.sites +
150
			escapeHTML(entry.site));
151
		tmpl = tmpl.replace(/%%path%%/g, escapeHTML(entry.path));
152
153
		if (entry.options.private === '1') {
154
			tmpl = tmpl.replace(/%%private%%/g, escapeHTML(entry.options.private));
155
		}
156
157
		return tmpl;
158
	}
159
160
161
};